#@layout() #define main()
<div class="xp-layout">
	<form id="userForm" action="xpUser/edit" method="post" class="layui-form layui-form-pane">
		<input type="hidden" name="user.id" value="#(user.id??)" />
			<div class="layui-form-item">
				<div class="layui-col-md6 layui-col-sm6 xp-col-padding5">
					<div class="layui-col-md12 layui-col-sm12">
						<label class="layui-form-label">用户名</label>
						<div class="layui-input-block">
							<input type="text" id="userName" name="user.USERNAME" value="#(user.USERNAME??)" lay-verify="required|userName" autocomplete="off" maxlength="50" placeholder="请输入用户名" class='layui-input xp-disable-btn' readonly="readonly">
						</div>

					</div>
					<div class="layui-col-md12 layui-col-sm12">
						<div class="layui-input-block layui-word-aux">
							默认密码888888 #if(bResetPassword)
							<a style="padding-left: 20px;" href="xpUser/resetPassword?id=#(user.ID??)">密码初始化</a>
							#end
						</div>
					</div>
					<div class="layui-col-md12 layui-col-sm12">
						<label class="layui-form-label">姓名</label>
						<div class="layui-input-block">
							<input type="text" name="user.NAME" value="#(user.NAME??)" autocomplete="off" maxlength="20" lay-verify="required" placeholder="请输入姓名" class="layui-input">
						</div>
					</div>
				</div>
				<div class="layui-col-md6 layui-col-sm6 xp-col-padding5">
					<div class="layui-input-block">
						<div class="site-demo-upload">
							<img id="img_photo" src="#(detail.photo??'_common/img/userphoto.jpg')">
						</div>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-col-md6 layui-col-sm6 xp-col-padding5">
					<label class="layui-form-label">手机号</label>
					<div class="layui-input-block">
						<input type="text" name="user.PHONE" value="#(user.PHONE??)" lay-verify="required" autocomplete="off" maxlength="20" placeholder="请输入手机号" class="layui-input">
					</div>
				</div>
				<div class="layui-col-md6 layui-col-sm6 xp-col-padding5">
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-block">
						<input type="text" name="user.EMAIL" value="#(user.EMAIL??)" lay-verify="" autocomplete="off" placeholder="请输入邮箱" maxlength="100" class="layui-input">
					</div>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-col-md6 layui-col-sm6 xp-col-padding5">
					<label class="layui-form-label">部门</label>
					<div class="layui-input-block">
						<select id="departmentID" name="user.DEPARTMENTID" lay-filter="changebh"> 
						#@option(departmentList,"id","name",user.DEPARTMENTID??!=null ? (user.DEPARTMENTID??) : departmentID,false)
						</select>
					</div>
				</div>
				<div class="layui-col-md6 layui-col-sm6 xp-col-padding5">
					<label class="layui-form-label">用户类型</label>
					<div class="layui-input-block">
						<select name="user.TYPE" id="type" lay-filter="changetype">
							#if(user.TYPE??"-1"=="0")
								#setLocal(typeList=[{value:2,name:"操作员"},{value:1,name:"管理员"},{value:0,name:"超级管理员"}])
							#else
								#setLocal(typeList=[{value:2,name:"操作员"},{value:1,name:"管理员"}])
							#end
							#@option(typeList,"value","name",user.TYPE??,false)
						</select>
					</div>
				</div>
			</div>
			<div class="layui-form-item" id="role">
				<div class="layui-col-md12 layui-col-sm12 xp-col-padding5">
					<label class="layui-form-label">角色</label>
					<div class="layui-input-block">
						#for(x : roleList)
							<input type="checkbox" name="role" lay-skin="primary" title="#(x.name)" value="#(x.id)" #(x.checked?"checked":"")>
						#end
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-col-md12 layui-col-sm12 xp-col-padding5">
					<label class="layui-form-label">IP限制</label>
					<div class="layui-input-block">
						<input type="text" name="user.LIMITIP" value="#(user.LIMITIP??)" maxlength="20" placeholder="多个IP用逗号隔开" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div style="text-align: center;">
					<button class="layui-btn" lay-submit="" lay-filter="go">立即提交</button>
				</div>
			</div>
	</form>
	<script type="text/javascript">
		
			layui.use(['form', 'laydate'], function(){
				var form = layui.form
				,layer = layui.layer
				,laydate = layui.laydate;


				//自定义验证规则
				form.verify({
					userName: function(value){
						if(value.length < 5){
							return '用户名至少得5个字符啊';
						}
					},
				});

				//监听指定开关
				form.on('select(changebh)', function(data){
					if(data.value!="#(departmentID)")
					{
						$("#role").css("display","none");
						$("input[name='role']").removeAttr("checked");
						form.render('checkbox');
					}
					else
					{
						if($("#type").val()=="2")
							$("#role").css("display","block");
						else
						{
							$("#role").css("display","none");
							$("input[name='role']").removeAttr("checked");
						}
						form.render('checkbox');
					}
				});
				
				//监听指定开关
				form.on('select(changetype)', function(data){
					console.log(data.value=="1");
					if(data.value=="1"){
						$("#role").css("display","none");
						$("input[name='role']").removeAttr("checked");
						form.render('checkbox');
					}else{
						if($("#departmentID").val()=="#(departmentID)")
							$("#role").css("display","block");
						else{
							$("#role").css("display","none");
							$("input[name='role']").removeAttr("checked");
						}
						form.render('checkbox');
					}
				});
				
				//监听指定开关
				form.on('switch(switchState)', function(data){
					$("#userstate").val(this.checked ? '1' : '0');
				});

				//监听提交
				form.on('submit(go)', function(data){
					var url = $('#userForm').attr('action');
					$.post(url, $('#userForm').serialize(), function(res) {
						if (res.result == 1) {
							layer.msg(res.msg, {
								icon : 1,
								time : 1000
							}, function() {
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index); //再执行关闭  
								parent.reloadList();//重新reload列表
							});
						} else {
							layer.msg(res.msg, {
								icon : 5
							});
						}
					});
					return false;
				});
				
				if(#(bSelf ? 1 :0)){
					$("#departmentID").attr("disabled","disabled");
					$("#type").attr("disabled","disabled");
					form.render('select'); //这个很重要
					$("input[name='role']").attr("disabled","disabled");
					form.render('checkbox'); //这个很重要
				}
				if($("#type").val()!="2"){
					$("#role").css("display","none");
				}
			});
	</script>
</div>
#end
